/**
 *
 */
package steven.gui.console.shell;

import java.util.Locale;

import steven.gui.console.Console;
import steven.gui.console.ConsoleController;

/**
 * @author steven.lam.t.f
 *
 */
public class ShellConsole extends Console{
	private static final long serialVersionUID = -5688347372206646009L;

	public ShellConsole(final ConsoleController controller){
		super(controller);
	}
	@Override
	protected void onCreate(){
		super.getInputContext().selectInputMethod(Locale.US);
		super.appendText(">");
	}
	@Override
	protected void processInput(final String input){
		super.appendText(input);
		super.appendNewLine();
		super.getInputLine().clear();
		final String trimmedInput = input.trim();
		if("exit".equalsIgnoreCase(trimmedInput)){
			super.getController().terminate();
		}else if("clear".equalsIgnoreCase(trimmedInput)){
			super.clear();
			super.appendText(">");
		}else{
			super.appendText("Unrecognized command.");
			super.appendNewLine();
			super.appendText(">");
		}
	}
}
